//---------------------------------------------------------------------------
#pragma hdrstop

#include "CommonClass.h"
//---------------------------------------------------------------------------

#pragma package(smart_init)


__fastcall TPassTrack::TPassTrack()
{
   MinTrackNumber = 0;
   MaxTrackNumber = 0;
   AllTrack = true;
}

//---------------------------------------------------------------------------
void __fastcall TPassTrack::SetMinMaxTrack(unsigned short MinTrack, unsigned short MaxTrack)
{
   AllTrack = false;
   if (MinTrack < MaxTrack)
   {
      MinTrackNumber = MinTrack;
      MaxTrackNumber = MaxTrack;
   }
   else
   {
      MinTrackNumber = MaxTrack;
      MaxTrackNumber = MinTrack;
   }
}

//---------------------------------------------------------------------------
void __fastcall TPassTrack::SetAllTrack(void)
{
   MinTrackNumber = 0;
   MaxTrackNumber = 0;
   AllTrack = true;
}

//---------------------------------------------------------------------------
bool __fastcall TPassTrack::PassIt(const unsigned short CutTrackNumber)
{
   if (AllTrack) return true;
   if (CutTrackNumber <= MaxTrackNumber && CutTrackNumber >= MinTrackNumber)
      return true;
   else
      return false;
}

//---------------------------------------------------------------------------
void __fastcall TPassTrack::Save(const int Handle)
{
   WriteFloat(Handle, MinTrackNumber);
   WriteFloat(Handle, MaxTrackNumber);
   WriteBool(Handle, AllTrack);
};

//---------------------------------------------------------------------------
void __fastcall TPassTrack::Load(const int Handle)
{
   MinTrackNumber = ReadFloat(Handle);
   MaxTrackNumber = ReadFloat(Handle);
   AllTrack = ReadBool(Handle);
};

//---------------------------------------------------------------------------
TPassTrack & __fastcall TPassTrack::operator = (const TPassTrack & t)
{
   MinTrackNumber = t.MinTrackNumber;
   MaxTrackNumber = t.MaxTrackNumber;
   AllTrack = t.AllTrack;
   return *this;
}

//---------------------------------------------------------------------------
void __fastcall Array::Delete(const unsigned short Index)
{
   p = &at(Index);
   erase(p);
}

//---------------------------------------------------------------------------
void __fastcall Array::Insert(const unsigned short Index, ArrayItems Datas)
{
	p = &at(Index);
	insert(p, Datas);
}

void __fastcall Array::InsertNew(const int Index)
{
	ArrayItems Item;
	Insert(Index, Item);
	return;
}

void __fastcall Array::Move(const int From, const int To)
{
	int Del;
	if (To < From)
		Del = From + 1;
	else
		Del = From;
	if (To == size() -1)
		push_back(at(From));
	else
		insert(begin() + To, at(From));
	erase(begin() + Del);
	return;
}

void __fastcall Array::ToFirst(const int Index)
{
	Move(Index, 0);
	return;
}

void __fastcall Array::ToLast(const int Index)
{
	Move(Index, size() - 1);
	return;
}

void __fastcall Array::ToPrevious(const int Index)
{
	if (Index == 0) return;
	Move(Index, Index - 1);
	return;
}

void __fastcall Array::ToNext(const int Index)
{
	if (Index == size() - 1) return;
	Move(Index, Index + 1);
	return;
}

void __fastcall Array::AddNew(void)
{
	ArrayItems Item;
	push_back(Item);
	return;
}

void __fastcall ArrayItems::Delete(const int Index)
{
	p = &at(Index);
	erase(p);
	return;
}

void __fastcall ArrayItems::Insert(const int Index, const float Item)
{
	p = &at(Index);
	insert(p, Item);
	return;
}

void __fastcall ArrayItems::Move(const int From, const int To)
{
	int Del;
	if (To < From)
		Del = From + 1;
	else
		Del = From;
	if (To == size() -1)
		push_back(at(From));
	else
		insert(begin() + To, at(From));
	erase(begin() + Del);
	return;
}

void __fastcall ArrayItems::ToFirst(const int Index)
{
	Move(Index, 0);
	return;
}

void __fastcall ArrayItems::ToLast(const int Index)
{
	Move(Index, size() - 1);
	return;
}

void __fastcall ArrayItems::ToPrevious(const int Index)
{
	if (Index == 0) return;
	Move(Index, Index - 1);
	return;
}

void __fastcall ArrayItems::ToNext(const int Index)
{
	if (Index == size() - 1) return;
	Move(Index, Index + 1);
	return;
}

void __fastcall ArrayItems::WriteAdvStringGrid(TAdvStringGrid * AdvStringGrid)
{
	int i;
	AdvStringGrid->ClearRows(1, AdvStringGrid->RowCount - 1);
	for (i = 1; i < size(); i++) {
		AdvStringGrid->Ints[0][i] = i;
		AdvStringGrid->Floats[1][i] = at(i - 1);
	}
	return;
}

void __fastcall ArrayItems::ReadAdvStringGrid(TAdvStringGrid * AdvStringGrid)
{
	int i;
	resize(AdvStringGrid->RowCount - 1);
	if (AdvStringGrid->RowCount < 2) return;
	for (i = 1; i < AdvStringGrid->RowCount; i++)
		at(i - 1) = AdvStringGrid->Floats[1][i];
	return;
}


